package com.example.netty.IO;

import com.google.common.util.concurrent.ThreadFactoryBuilder;

import java.io.IOException;
import java.net.Socket;
import java.util.Date;
import java.util.concurrent.*;

/**
 * @author liupk
 * @date 2018/10/23
 */
public class IOClient {
    
    public static void main(String[] args) throws IOException {
        Socket socket = new Socket("127.0.0.1",8002);
        ExecutorService executorService = Executors.newCachedThreadPool();
        executorService.execute(() -> {
            while (true){
                try {
                    socket.getOutputStream().write((new Date() + ": hello world").getBytes());
                    Thread.sleep(2000);
                } catch (IOException e) {
                    e.printStackTrace();
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        });
        executorService.shutdown();
    }
}